package com.koo.modules.b2b.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.b2b.dao.B2bCompanyInfoDao;
import com.koo.modules.b2b.entity.B2bCompanyInfoEntity;
import com.koo.modules.b2b.service.B2bCompanyInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
public class B2bCompanyInfoServiceImpl extends ServiceImpl<B2bCompanyInfoDao, B2bCompanyInfoEntity> implements B2bCompanyInfoService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<B2bCompanyInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(MyStrUtil.isNotEmpty(key), B2bCompanyInfoEntity::getCompanyName, key)
                .or().eq(MyStrUtil.isNotEmpty(key), B2bCompanyInfoEntity::getCompanyNo, key);

        IPage<B2bCompanyInfoEntity> page = this.page(
                new Query<B2bCompanyInfoEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}